package com.hk.redundantcode.reflection.right;


import java.math.BigDecimal;
import java.math.RoundingMode;

public enum BankAPIFieldTypeEnum {

    S {
        @Override
        public String format(Object value, BankAPIField bankAPIField) {
            return String.format("%-" + bankAPIField.length() + "s", value.toString()).replace(' ', '_');
        }
    },
    N {
        @Override
        public String format(Object value, BankAPIField bankAPIField) {
            return String.format("%" + bankAPIField.length() + "s", value.toString()).replace(' ', '0');
        }
    },
    M {
        @Override
        public String format(Object value, BankAPIField bankAPIField) {
            return String.format("%0" + bankAPIField.length() + "d", ((BigDecimal) value).setScale(2, RoundingMode.DOWN).multiply(new BigDecimal("100")).longValue());
        }
    };

    //枚举中可以定义抽象的方法，之后所有的成员都必须实现这个方法
    public abstract String format(Object value, BankAPIField bankAPIField);

}
